package cn.appsys.tools;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/**
 * 验证是否登陆的过滤器
 * @author 寇超强
 *
 */
public class SysInterceptor extends HandlerInterceptorAdapter {
	private Logger logger=Logger.getLogger(SysInterceptor.class);
	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		logger.debug("SysInterceptor preHandler");
		HttpSession session=request.getSession();
		if(session.getAttribute(Constants.USER_SESSION)==null && session.getAttribute(Constants.DEV_USER_SESSION)==null){
			response.sendRedirect(request.getContextPath()+"/index.jsp");
			return false;
		}
		return true;
	}

}
